<!doctype html>
<html>

	<head>
		<meta charset="UTF-8">
		<title></title>
		<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<link href="../../css/mui.min.css" rel="stylesheet" />
		<link rel="stylesheet" type="text/css" href="../../css/my/integral.css" />
	</head>

	<body>
		<div id="integral" v-cloak>
			<header class="mui-bar mui-bar-nav">
				<a class="mui-action-back mui-icon mui-icon-arrowleft mui-pull-left"></a>
				<h1 class="mui-title">积分商城</h1>
			</header>
			<div id="pullrefresh" class="mui-content mui-scroll-wrapper">
				<div class="mui-scroll">
					<div class="integral_list" v-for="list in list" @tap="openDetail(list)">
						<div class="integral_img"><img v-lazy="imgCommonUrl + list.prodImage" /></div>
						<div class="integral_main">
							<div class="title">{{list.name}}</div>
							<div class="price">
								<span>
			    				积分: {{list.exchangeIntegral}}
			    			</span>
								<span>价格: ￥{{list.price}}</span>
							</div>
						</div>
						<div class="exchange">
							<button type="button" class="mui-btn mui-btn-danger" @tap.stop="exchange(list)">兑换</button>
						</div>
					</div>
					<div></div>
				</div>
			</div>

			<div class="noshopp">
				<img src="../../images/noshop.png" alt="" />
				<div>没有可以兑换的商品</div>
			</div>

			<div class="caching" v-show="confirAlert">
				<div class="caching_img">
					<img src="../../images/clear_success.png" />
				</div>
				<div>兑换成功</div>
			</div>

			<div class="confirmation" :class="{show:id}">
				<div class="confirmation_title">确定要兑换此商品？</div>
				<div class="confirmation_success" @tap="confirm">确定</div>
				<div @tap="cancel">取消</div>
			</div>

		</div>
		<script src="../../js/mui.min.js"></script>
		<script src="../../js/libs/zepto.js"></script>
		<script src="../../js/libs/vue.js"></script>
		<script src="../../js/libs/vue-lazyload.js"></script>
		<script src="../../js/common.js"></script>
		<script type="text/javascript">
			mui.init({
				pullRefresh: {
					container: '#pullrefresh',
					up: {
						auto: true,
						contentrefresh: '正在加载...',
						callback: pullupRefresh
					}
				}
			})
			var swith = false
			Vue.use(VueLazyload, {
				preLoad: 1.3,
				error: '../../images/noimg.jpg',
				loading: '../../images/noimg.jpg'
			});
			var mask = mui.createMask(callback); //callback为用户点击蒙版时自动执行的回调；
			var integral = new Vue({
				el: '#integral',
				data: {
					imgCommonUrl: common.imageUrl,
					pageNum: 1,
					list: [],
					id: '',
					confirAlert: false
				},
				methods: {
					exchange: function(data) {
						this.id = data.id
						mask.show()
					},
					cancel: function() {
						mask.close()
					},
					confirm: function() {
						if(swith) {
							return
						}
						swith = true
						common.ajax('/integral/submitOrder', {
								id: integral.id,
								count: 1
							},
							function(data) {
								swith = false
								if(data.code == 1) {
									integral.confirAlert = true
									mask.close()
									setTimeout(function() {
										integral.confirAlert = false
									}, 2000)
										var list = plus.webview.getWebviewById('../my/myintegral.html')
										mui.fire(list, 'myintegral');
								} else {
									mask.close()
									if(data.resultMsg) {
										common.toast(data.resultMsg)
									}
								}
							})
					},
					openDetail:function(data){
						common.open('integralmall.html','integralmall.html',data.id)
					}

				}
			})

			function pullupRefresh() {
				$(".noshopp").hide()
				$('.mui-pull-bottom-pocket').css('display', 'block !important')
				common.ajax('/integral/productList', {
					curPageNO: integral.pageNum++
				}, function(data) {
					if(data.code == 1) {
						if(integral.pageNum > data.data.pageCount) {
							mui('#pullrefresh').pullRefresh().endPullupToRefresh(true);
						} else {
							mui('#pullrefresh').pullRefresh().endPullupToRefresh();
						}
						integral.list = data.data.list
						if(integral.list.length <= 0) {
							$(".noshopp").show()
							$('.mui-pull-bottom-pocket').css('display', 'none !important')
						} else {
							$(".noshopp").hide()
							$('.mui-pull-bottom-pocket').css('display', 'block !important')
						}

					} else {
						mui('#pullrefresh').pullRefresh().endPullupToRefresh();
						if(data.resultMsg) {
							common.toast(data.resultMsg)
						}
					}
				}, true, 'get')
			}

			function callback() {
				integral.id = ''
			}
		</script>
	</body>

</html>